﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_v5_kanne", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedV5Kanne))]
    public class DetailandmedV5KanneSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedV5Kanne clazz;
        
        public DetailandmedV5KanneSerializer(IDetailandmedV5Kanne clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.KirjeId!=null) {
                Writer.WriteStartElement("kirje_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.KirjeId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeNr!=null) {
                Writer.WriteStartElement("kande_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.KandeNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeKpv!=null) {
                Writer.WriteStartElement("kande_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.KandeKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kandeliik!=null) {
                Writer.WriteStartElement("kandeliik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kandeliik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeliikTekstina!=null) {
                Writer.WriteStartElement("kandeliik_tekstina");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeliikTekstina))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kirje_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_kanne>kirje_id");
                }
                clazz.KirjeId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kirje_id")).Value;
            }
            if (Reader.LocalName=="kande_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_kanne>kande_nr");
                }
                clazz.KandeNr = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kande_nr")).Value;
            }
            if (Reader.LocalName=="kande_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_kanne>kande_kpv");
                }
                clazz.KandeKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kande_kpv")).Value;
            }
            if (Reader.LocalName=="kandeliik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_kanne>kandeliik");
                }
                clazz.Kandeliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandeliik")).Value;
            }
            if (Reader.LocalName=="kandeliik_tekstina") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_kanne>kandeliik_tekstina");
                }
                clazz.KandeliikTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandeliik_tekstina")).Value;
            }
        }
    }
}
